package com.situ.day2;

import org.junit.Test;

import java.util.Random;
import java.util.Scanner;

public class IfWhileDemo {
    @Test
    public void test1() {
        int score = 2;
        if (3 >= 5) {
            System.out.println("3 >= 5");
        } else {
            System.out.println("3 < 5");
        }
    }

    /*
        >=90   <=100      优秀
        >=80    <90       良好
        >=70    <80       一般
        >=60    <70      及格
        <60              不及格
    */
    @Test
    public void test2() {
        //int score = 48;
        //Scanner可以帮助我们完成从控制台Console输入数据
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入成绩：");
        int score = scanner.nextInt();
        //卫操作
        if (score < 0) {
            System.out.println("这是非法的输入:小于0");
            return;
        }
        if (score < 0) {
            System.out.println("这是非法的输入: >100");
            return;
        }

        if (score >= 90 && score <= 100) {
            System.out.println("优秀");
        } else if (score >= 80 && score < 90) {
            System.out.println("良好");
        } else if (score >= 70 && score < 80) {
            System.out.println("一般");
        } else if (score >= 60 && score < 70) {
            System.out.println("及格");
        } else {
            System.out.println("不及格");
        }
    }

    @Test
    public void test7() {
        int num1 = 23;
        int num2 = 14;
        int max1 = 0;
        if (num1 >= num2) {
            max1 = num1;
        } else {
            max1 = num2;
        }
        System.out.println(max1);

        int max2 = num1 >= num2 ? num1 : num2;
        System.out.println(max2);
    }

    @Test
    public void test8() {
        int age = 23;
        System.out.println("我的年龄是23岁");
        //豆豆加加
        System.out.println("我的年龄是" + age + "岁");

    }

    @Test
    public void test11() {
        //while
        int i = 1;
        while (i <= 5) {
            System.out.println("HelloWorld");
            i++;
        }
        System.out.println("---------------------");
        // i,j,k
        for (int j = 1; j <= 5; j++) {
            System.out.println("HelloWorld");
        }
    }

    @Test
    public void test17() {
        int sum = 0;
        for (int i = 1; i <= 100; i++) {
            System.out.println(i);
            //sum = sum + i;
            sum += i;
            System.out.println("sum: " + sum);
        }
        System.out.println("sum: " + sum);
    }

    //统计思想，数一下符合条件的有多少个（计算1-100以内7的倍数的个数）
    @Test
    public void test34() {
        int count = 0;
        for (int i = 1; i <= 100; i++) {
            if (i % 7 == 0) {
                System.out.println(i);
                count++;
            }
        }
        System.out.println("count: " + count);
    }

    @Test
    public void test44() {
        for (int i = 1; i <= 5; i++) {
            if (i == 3) {
                continue;
            }
            System.out.println(i);
        }
    }

    @Test
    public void test45() {
        for (int i = 1; i <= 5; i++) {
            if (i == 3) {
                break;
            }
            System.out.println(i);
        }
    }

    @Test
    public void test33() {
        for (int i = 1; i <= 5; i++) {
            System.out.println("i: " + i);
            for (int j = 1; j <= 5; j++) {
                if (j == 3) {
                    break;
                }
                System.out.println("j: " + j);
            }
        }
    }

    @Test
    public void test66() {
        //parameter:参数
        //Params: bound – the upper bound (exclusive). Must be positive.
        //int value between zero (inclusive) and bound (exclusive)
        // [0,100) + 1 = [1,101)
        Random random = new Random();
        int num = random.nextInt(100) + 1;
        System.out.println(num);
        while (true) {

        }
    }

    //    ****
//    ****
//    ****
    @Test
    public void test22() {
        //****
        for (int i = 1; i <= 4; i++) {
            System.out.print("*");
        }
        //单纯换行
        System.out.println();
        //*
        //*
        //*
        for (int i = 1; i <= 3; i++) {
            System.out.println("*");
        }
    }

    @Test
    public void test23() {
        //i:1
        for (int i = 1; i <= 3; i++) {
            for (int j = 1; j <= 4; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

    //    *
//    **
//    ***
//    ****
//    *****
    @Test
    public void test24() {
        // i:1  j:1
        // i:2  j:2
        // i:3  j:3
        for (int i = 1; i <= 5; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

    @Test
    public void test241() {
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= i; j++) {
                //System.out.print("2*6=12\t");
                System.out.print(j + "*" + i + "=" + (i * j) + "\t");
            }
            System.out.println();
        }
    }

    @Test
    public void test134() {
        int num = 13;
        switch (num) {
            case 1:
                System.out.println(1);
                break;
            case 2:
                System.out.println(2);
                break;
            case 3:
                System.out.println(3);
                break;
            default:
                System.out.println("default");
                break;
        }
    }

//    输入月份判断天数：
//    1、3、5、7、8、10、12  -------- 31天
//    4、6 、9、11--------------------30天
//    2----------------------------------28/29天
    @Test
    public void test88() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入月份：");
        int month = scanner.nextInt();
        switch (month) {
            case 1:
                System.out.println("31天");
                break;
            case 2:
                System.out.println("28/29天");
                break;
            case 3:
                System.out.println("31天");
                break;
            case 4:
                System.out.println("30天");
                break;
            case 5:
                System.out.println("31天");
                break;
            case 6:
                System.out.println("30天");
                break;
        }
    }

    @Test
    public void test89() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入月份：");
        int month = scanner.nextInt();
        switch (month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                System.out.println("31天");
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                System.out.println("30天");
                break;
            case 2:
                System.out.println("28/29天");

                break;
        }
    }

}
